package com.cy.pj.modules.service.impl;

import com.cy.pj.common.bo.PageObject;
import com.cy.pj.modules.entity.BaseShop;
import com.cy.pj.modules.mapper.BaseShopMapper;
import com.cy.pj.modules.service.IBaseShopService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商城基础设置Service业务层处理
 *
 * @author kiven
 * @date 2023-02-09
 */
@Service
public class BaseShopServiceImpl implements IBaseShopService
{
    @Autowired
    private BaseShopMapper baseShopMapper;


    @Value("${fz.pageHelper.pageSize}")
    private Integer pageSize;

    /**
     * 查询商城基础设置
     *
     * @param id 商城基础设置ID
     * @return 商城基础设置
     */
    @Override
    public BaseShop selectBaseShopById(Long id)
    {
        return baseShopMapper.selectBaseShopById(id);
    }

    /**
     * 查询商城基础设置列表
     *
     * @param baseShop 商城基础设置
     * @return 商城基础设置
     */
    @Override
    public PageObject<BaseShop> selectBaseShopList(BaseShop baseShop, Integer pageCurrent)
    {
        //1.参数校验
        if(pageCurrent==null||pageCurrent<1) {
            throw new IllegalArgumentException("页码值无效");
        }
        //2.设置分页参数
        String orderBy = "modify_time desc";
        Page<BaseShop> page= PageHelper.startPage(pageCurrent,pageSize,orderBy);
        //3.查询当前页记录
        List<BaseShop> list= baseShopMapper.selectBaseShopList(baseShop);
        return new PageObject<>(list, (int)page.getTotal(), page.getPages(), pageSize, pageCurrent);
    }

    /**
     * 新增商城基础设置
     *
     * @param baseShop 商城基础设置
     * @return 结果
     */
    @Override
    public int insertBaseShop(BaseShop baseShop)
    {
        return baseShopMapper.insertBaseShop(baseShop);
    }

    /**
     * 修改商城基础设置
     *
     * @param baseShop 商城基础设置
     * @return 结果
     */
    @Override
    public int updateBaseShop(BaseShop baseShop)
    {
        return baseShopMapper.updateBaseShop(baseShop);
    }

    /**
     * 删除商城基础设置对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteBaseShopByIds(String ids)
    {
        return baseShopMapper.deleteBaseShopByIds(ids.split(","));
    }

    /**
     * 删除商城基础设置信息
     *
     * @param id 商城基础设置ID
     * @return 结果
     */
    @Override
    public int deleteBaseShopById(Long id)
    {
        return baseShopMapper.deleteBaseShopById(id);
    }
}
